package com.lishe.lishe.lishe.utils;

import android.app.Activity;
import android.graphics.Bitmap;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.media.UMVideo;
import com.umeng.socialize.media.UMWeb;
import com.umeng.socialize.shareboard.ShareBoardConfig;

/**
 * Created by DELL on 2017/11/2.
 */

public class UMShareUtils {

    private static UMShareUtils umShareUtils;

    public static UMShareUtils getInstance(){
        if(umShareUtils==null){
            synchronized (UMShareUtils.class){
                umShareUtils=new UMShareUtils();
            }
        }

        return umShareUtils;
    }

    private UMShareUtils(){
    }

    /**
     *  分享纯文本到QQ、微信
     * @param activity
     * @param message
     * @param listener
     */
    public void sharedTextMessage(Activity activity, String message,UMShareListener listener){
        new ShareAction(activity)
                .withText(message)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }

    /**
     *  分享资源图片到QQ、微信
     * @param activity
     * @param message 图片描述
     * @param resId 资源图片id
     * @param listener
     */
    public void sharedImageResourseMessage(Activity activity,String message,int resId, UMShareListener listener){
        UMImage image=new UMImage(activity,resId);
        image.setDescription(message);

       new ShareAction(activity)
                .withMedia(image)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }

    /**
     *  分享Bitmap到QQ、微信
     * @param activity
     * @param message 图片描述
     * @param bmp bitmap
     * @param listener
     */
    public void sharedImageBitmapMessage(Activity activity, String message, Bitmap bmp, UMShareListener listener){
        UMImage image=new UMImage(activity,bmp);
        image.setDescription(message);
        ShareBoardConfig config = new ShareBoardConfig();
        config.setIndicatorVisibility(false);
        new ShareAction(activity)
                .withMedia(image)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open(config);
    }

    /**
     *
     * 分享网络图片到QQ、微信
     * @param activity
     * @param message
     * @param uri
     * @param listener
     */
    public void sharedInteretImageMessage(Activity activity,String message,String uri,UMShareListener listener){
        UMImage image=new UMImage(activity,uri);

        new ShareAction(activity)
                .withText(message)
                .withMedia(image)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }

    /**
     *  分享网页
     * @param activity
     * @param uri 网页url
     * @param webTitle 网页标题
     * @param webDescription 网页描述
     * @param thumbImageUrl 网页缩略图
     * @param listener
     */
    public void sharedWebMessage(Activity activity,String uri,String webTitle,String webDescription,String thumbImageUrl,UMShareListener listener){
        UMWeb web=new UMWeb(uri);
        web.setTitle(webTitle);
        web.setDescription(webDescription);
        web.setThumb(new UMImage(activity,thumbImageUrl));

        new ShareAction(activity)
                .withMedia(web)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }

    /**
     *  分享网络视频
     * @param activity
     * @param videoUri
     * @param videoTitle
     * @param videoDescription
     * @param thumbImageUrl 缩略图url
     * @param listener
     */
    public void sharedVideoMessage(Activity activity,String videoUri,String videoTitle,String videoDescription,String thumbImageUrl,UMShareListener listener) {
        UMVideo video=new UMVideo(videoUri);
        video.setThumb(new UMImage(activity,thumbImageUrl));
        video.setTitle(videoTitle);
        video.setDescription(videoDescription);

        new ShareAction(activity)
                .withMedia(video)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }

    /**
     *  分享网络音乐
     * @param activity
     * @param musicUri 网络音乐url
     * @param musicTitle
     * @param musicDescription
     * @param thumbImageUrl
     * @param listener
     */
    public void sharedMusicMessage(Activity activity,String musicUri,String musicTitle,String musicDescription,String thumbImageUrl,UMShareListener listener) {
        UMVideo video=new UMVideo(musicUri);
        video.setThumb(new UMImage(activity,thumbImageUrl));
        video.setTitle(musicTitle);
        video.setDescription(musicDescription);

        new ShareAction(activity)
                .withMedia(video)
                .setDisplayList(SHARE_MEDIA.WEIXIN, SHARE_MEDIA.WEIXIN_CIRCLE,SHARE_MEDIA.QQ, SHARE_MEDIA.QZONE)
                .setCallback(listener)
                .open();
    }
}
